﻿using System;
//using System.Diagnostics.Contracts;
using System.Linq;
using CardGamesLibrary.Tables;
using CardGamesLibrary.Turns;

namespace CardGamesLibrary.Poker
{
    public abstract class PokerTableTurn : TableTurn
    {
        private readonly PokerTable _table;

        protected PokerTableTurn(PokerTable table) : base(table.Seats)
        {
            _table = table;
        }

        public override void Play()
        {
           // deal cards
            DealCards();
            
            // collect the bets
            CurrentBet = _table.BigBlind;
            CollectBets();
             
            base.Play();
            
        }

        internal int CurrentBet { get; set; }

        protected virtual void CollectBets()
        {
            foreach (var seat in _table.Seats.Where(a=>a.Player != null).OfType<PokerSeat>())
            {
                seat.CollectBet();
            }
        }

        protected abstract void DealCards();

        protected override void PlayPlayerTurn(TableSeat seat)
        {
            Console.WriteLine(" > {0}", seat.Player.Name);
            seat.Player.PlayTurn(new PokerPlayerTurn(this));
        }
    }
}